//
//  BookMakerFilteringImageView.m
//  BookMaker
//
//  Created by Mathieu Tozer on 27/11/07.
//  Copyright 2007 plasq. All rights reserved.
//

#import "BookMakerFilteringImageView.h"
#import "Image.h"

@implementation BookMakerFilteringImageView

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if (object == _imagesArayController && [keyPath isEqualToString:@"selection"]) {
		Image *selection = [self currentImage];
		if (selection) {
			NSString *path = [[selection valueForKey:@"path"] stringByExpandingTildeInPath];
			NSString *escapedString = [[NSString stringWithFormat:@"file://%@", path] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
			NSURL *url = [NSURL URLWithString:escapedString];
			if ([selection isFirstLoad] && _previousSelection) {
				[selection copyPagesFrom:_previousSelection];
			}
			_previousSelection = selection;
			
			[self openImageURL:url];
		}
	}
	else {
		[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
	}
}

- (void)awakeFromNib
{
	[self setDelegate:self];
	[super awakeFromNib];
}

- (IBAction)_zoomImageToFit:(id)sender
{
	[super zoomImageToFit:sender];
}


- (void)shiftMouseDown:(NSEvent *)event
{

}

- (void)mouseDown:(NSEvent *)event
{
	[super mouseDown:event];
}
@end
